<form id="task_intercept_form" lay-filter="task_intercept_form" class="layui-form model-form">
    <input name="id" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label">发布者ID</label>
        <div class="layui-input-block">
            <input id="userId" class="layui-input" readonly="readonly" style="border-color: white;outline: none;border: 0">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">任务编号</label>
        <div class="layui-input-block">
            <input id="tkcode" class="layui-input" readonly="readonly" style="border-color: white;outline: none;border: 0">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">你的ID</label>
        <div class="layui-input-block">
            <input id="loguser" class="layui-input" readonly="readonly" style="border-color: white;outline: none;border: 0">
        </div>
    </div>
    <div id="myPhone" class="layui-form-item">
        <label class="layui-form-label">你的手机号</label>
        <div class="layui-input-block">
            <input id="phone1" class="layui-input" readonly="readonly" style="border-color: white;outline: none;border: 0">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">留言方式</label>
        <div class="layui-input-block">
            <input type="radio" name="repway" value="0" title="线上留言"/>
            <input type="radio" name="repway" value="1" title="线下留言"/>
        </div>
    </div>

    <div id="content" class="layui-form-item">
        <label class="layui-form-label">留言内容</label>
        <div class="layui-input-block">
            <textarea id="repcon" name="repcon"></textarea>
        </div>
    </div>
        <div class="layui-form-item model-form-footer">
            <button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
            <button class="layui-btn" lay-filter="task_intercept_form-submit" lay-submit>保存</button>
        </div>
</form>

<script>
    layui.use(['layer', 'admin', 'form', 'tinymce'], function () {
        // let layer = layui.layer;
        let form = layui.form;
        let tinymce = layui.tinymce;
        let admin = layui.admin;
        let index = layui.index;
        let userinfo = '';

        var login_user;
        // 获取当前用户信息
        index.getUser(function (user) {
            login_user = user;
        });

        userinfo=admin.getTempData('t_taskIntercept');
        //线上回复信息赋值
        $("#loguser").val(login_user.id);
        $("#userId").val(userinfo.userid);
        $("#tkcode").val(userinfo.tkcode);
        $("#phone1").val(login_user.phone);
        //渲染富文本框
        tinymce.render({
            elem: "#repcon",
            height: '400px'
            // 支持tinymce所有配置
        }, (opt, edit) => {
            // 加载完成后回调 opt 是传入的所有参数
            // edit是当前编辑器实例，等同于t.get返回值
        });
        let edit = tinymce.get("#repcon");
        form.render('radio');

        $("#content").hide();
        $("#myPhone").hide();
        //判断单选框的选取状态
        form.on('radio', function (data) {
            if (data.value == 1) {
                $("#content").hide();
                layer.open({
                    content:'线下回复会把你的电话发送给作者'
                })
                $("#myPhone").show();
                $("#phone1").val(login_user.phone);
            } else if (data.value == 0) {
                $("#content").show();
                $("#myPhone").hide();
                $("#phone1").val("");
            }
        });

        // 表单提交事件
        form.on('submit(task_intercept_form-submit)', function (data) {
            layer.load(2);
            let loguser = login_user.id;
            let tkcode = userinfo.tkcode;
            let userId = userinfo.userid;
            let repcon = edit.getContent();
            let phone = $("#phone1").val();
            let repway=$("input[name=repway]:checked").val();

            let task = {
                loguser : loguser,
                tkcode: tkcode,
                userId: userId,
                repcon: repcon,
                phone: phone,
                repway: repway
            };
            if (data.field.repway==1){
                task.repcon='';
            }
                admin.req('api-task/task/onlineReply ', JSON.stringify(task), function (data) {
                layer.closeAll('loading');
                if (data.code == 0) {
                    layer.msg(data.msg, {icon: 1, time: 500});
                    admin.finishPopupCenter();
                } else {
                    layer.msg(data.msg, {icon: 2, time: 1500});
                }
            }, "POST");
            return false;
        });
    });
</script>